package handler

import (
	"github.com/gin-gonic/gin"
	"mock-exam2/model"
	"strconv"
)

func EmployAdd(c *gin.Context) {
	name := c.PostForm("name")
	employeeStatus := c.PostForm("employee_status")
	workNum, _ := strconv.Atoi(c.PostForm("work_num"))
	employee := model.Employee{
		Name:           name,
		EmployeeStatus: employeeStatus,
		WorkNum:        workNum,
	}
	model.DB.Create(&employee)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func WorkAdd(c *gin.Context) {
	CustomerName := c.PostForm("customer_name")
	WorkStatus := c.PostForm("work_status")
	eid, _ := strconv.Atoi(c.PostForm("eid"))
	work := model.Work{
		Eid:          eid,
		WorkStatus:   WorkStatus,
		CustomerName: CustomerName,
	}
	model.DB.Create(&work)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func WorkList(c *gin.Context) {
	var employeework []model.EmployeeWork
	model.DB.Table("works").
		Select("works.id as Wid",
			"employees.name as Name",
			"employees.employee_status as EmployeeStatus",
			"employees.work_num as WorkNum",
			"works.work_status as WorkStatus",
			"works.customer_name as CustomerName").
		Joins("left join employees on employees.id =works.eid").
		Find(&employeework)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": employeework,
	})
}
